from proxy.Manager.ProxyManager import ProxyManager
import requests
from bs4 import BeautifulSoup as bs
from flask import jsonify

def getMovie(url):
    proxy = ProxyManager().get()
    # proxies = {"https": "https://{proxy}".format(proxy=proxy)}
    # page = requests.get(url, proxies=proxies)
    page = requests.get(url)
    content = page.content.decode("utf-8")
    soup = bs(content, "html.parser")
    nowplaying_movie = soup.find_all('div', id='nowplaying')
    nowplaying_movie_list = nowplaying_movie[0].find_all('li', class_='list-item')
    nowplaying_list = []
    for item in nowplaying_movie_list:
        nowplaying_dict = {}
        nowplaying_dict['id'] = item['data-subject']
        for tag_img_item in item.find_all('img'):
            nowplaying_dict['name'] = tag_img_item['alt']
            nowplaying_list.append(nowplaying_dict)
    return str(nowplaying_list).encode("utf-8")


if __name__ == "__main__":
    getMovie("https://movie.douban.com/cinema/nowplaying/hangzhou/")